ifeq ($(HAVE_DOT_CONFIG),y)
all: lib
else
all: defconfig
endif

include $(top_srcdir)bin/Makefile.in
include $(top_srcdir)include/Makefile.in
include $(top_srcdir)src/Makefile.in
include $(top_srcdir)extra/Makefile.in

$(headers-y) $(libcxx-a-y) $(libcxx-so-y): include/system_configuration.h

tests: lib
	$(Q)$(MAKE) -C tests all

check test: tests
	$(Q)$(MAKE) -C tests test

release:
	$(RM) ../uClibc++-$(VERSION).tar
	git archive --format=tar --prefix=uClibc++-$(VERSION)/ HEAD \
		> ../uClibc++-$(VERSION).tar
	cat ../uClibc++-$(VERSION).tar | bzip2 -c9 > ../uClibc++-$(VERSION).tar.bz2
	cat ../uClibc++-$(VERSION).tar | xz -e -c8 > ../uClibc++-$(VERSION).tar.xz
	du -b $(addprefix ../uClibc++-$(VERSION).tar.,bz2 xz)

install: install-bin install-include install-lib

clean: CLEAN_bin CLEAN_src
	#$(MAKE) -C $(top_builddir)extra/locale clean

realclean: clean DISTCLEAN_extra DISTCLEAN_include DISTCLEAN_src
distclean: realclean DISTCLEAN_.config
DISTCLEAN_.config:
	$(do_rm) $(addprefix $(top_builddir),.config .config.cmd .config.old)

#Menu configuration system

extra/config/conf:
	$(Q)$(MAKE) -C extra/config conf

extra/config/mconf:
	$(Q)$(MAKE) -C extra/config ncurses mconf

menuconfig: extra/config/mconf
	$(Q)$< extra/Configs/Config.in

config: extra/config/conf
	$(Q)$< extra/Configs/Config.in

oldconfig: extra/config/conf
	$(Q)$< -o extra/Configs/Config.in

silentoldconfig: extra/config/conf
	$(Q)$< -s extra/Configs/Config.in

randconfig: extra/config/conf
	$(Q)$< -r extra/Configs/Config.in

allyesconfig: extra/config/conf
	$(Q)$< -y extra/Configs/Config.in

allnoconfig: extra/config/conf
	$(Q)$< -n extra/Configs/Config.in

defconfig: extra/config/conf
	$(Q)$< -d extra/Configs/Config.in

include/system_configuration.h: .config | extra/config/conf
	$(Q)extra/config/conf -o extra/Configs/Config.in


ifeq ($(HAVE_DOT_CONFIG),)
.config: defconfig
endif

help:
	@echo 'Cleaning:'
	@echo '  clean			- delete temporary object files'
	@echo '  realclean		- delete temporary object files, including dependencies'
	@echo '  distclean		- delete all non-source files (including .config)'
	@echo
	@echo 'Build:'
	@echo '  all			- libraries'
	@echo
	@echo 'Configuration:'
	@echo '  allnoconfig		- disable all symbols in .config'
	@echo '  allyesconfig		- enable all symbols in .config (see defconfig)'
	@echo '  config		- text based configurator (of last resort)'
	@echo '  defconfig		- set .config to arch-specific defaults'
	@echo '  menuconfig		- interactive curses-based configurator'
	@echo '  oldconfig		- resolve any unresolved symbols in .config'
	@echo '  silentoldconfig	- resolve any unresolved symbols in .config, silently'
	@echo '  randconfig		- generate a random .config'
	@$(if $(arch-defconfigs), \
		@echo ''; \
		echo 'Architecture specific configs ($(ARCH))'; \
		$(foreach c, $(arch-defconfigs), \
			printf "  %-21s - Build for %s\\n" $(c) $(subst _defconfig,,$(c));) \
	)
	@echo
	@echo 'Installation:'
	@echo '  install		- install both the runtime and the headers'
	@echo
	@echo 'Development:'
	@echo '  check			- run testsuite'
	@echo '  tests			- compile testsuite binaries'
	@echo '  release		- create a distribution tarball'
	@echo
	@echo 'Environment variables:'
	@echo '  V="" 			- Quiet build (default)'
	@echo '  V=1			- Brief build (show defines, ld flags)'
	@echo '  V=2			- Very verbose build'
	@echo '  CROSS_COMPILE=	- Override CROSS_COMPILER_PREFIX from .config'
	@echo '  SHELL=		- Shell to use for make'
	@echo '  HOSTCC=		- C Compiler for compiling host binaries'
	@echo '  HOSTCXX=		- C++ Compiler for compiling host binaries'
	@echo '  HOSTCFLAGS=		- extra CFLAGS for compiling host binaries'
	@echo '  HOSTCXXFLAGS=		- extra CXXFLAGS for compiling host binaries'
	@echo '  HOSTLDFLAGS=		- extra LDFLAGS for linking host binaries'
	@echo
	@echo '  DESTDIR=		- Prepended prefix to installation paths'
	@echo '  CPU_CFLAGS		- extra C- and CXX- FLAGS for compiling uClibc++'
	@echo '  BUILD_EXTRA_LIBRARIES	- extra LDFLAGS for linking uClibc++ itself'
